<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>{$setting.webname}-添加角色</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link href="/static/admin/layui/css/layui.css" rel="stylesheet">
    <!--<link rel="shortcut icon" href="/favicon.ico">-->
    <link href="/static/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/static/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">

    <link href="/static/admin/css/animate.css" rel="stylesheet">
    <link href="/static/admin/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="/static/admin/css/plugins/iCheck/custom.css" rel="stylesheet">
    <style>
        .menuTitle{
            margin-top:10px;
            line-height: 35px;
            background:#cccccc;
            color:#000;
            padding-left:15px;
        }
    </style>


</head>

<body class="gray-bg">
    <div class="row wrapper border-bottom white-bg page-heading">
        <div class="col-sm-4">
            <h2>角色管理</h2>
            <ol class="breadcrumb">
                <li>
                    <a href="{:url('Index/admin')}">主页</a>
                </li>
                <li>
                    <strong>添加角色</strong>
                </li>
            </ol>
        </div>
    </div>
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
             <div class="col-sm-12">
			 
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>编辑角色信息</h5>
					</div>
                    <div class="ibox-content">
                        <form class="form-horizontal">
						    
                           <div class="form-group">
                                <label class="col-sm-2 control-label">角色名称：</label>
                                <div class="col-sm-4">
                                    <input type="text" placeholder="请输入角色名" id="r_name" class="form-control">
                                </div>
								<div class='col-sm-6'></div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">隶属于：</label>
                                <div class="col-sm-4">
                                    <select name="pid" id="pid" class="form-control">
                                        {foreach $roleslist as $vo}
                                           <option value="{$vo.r_id}">{$vo.r_name}</option>
                                        {/foreach}
                                    </select>
                                </div>
                                <div class='col-sm-6'></div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">排序：</label>
                                <div class="col-sm-4">
                                    <input type="number" placeholder="请输排序数字" id="sort" class="form-control">
                                </div>
                                <div class='col-sm-6'></div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">选择栏目权限：</label>
                                <div class="col-sm-4">
                                    {foreach $menu as $key=>$vo}
                                    <div class="menuTitle">{$vo.title}<input type="checkbox" id="parmenu{$key}" value="{$vo.id}" style="display: none"></div>
                                    <div class="checkbox i-checks">
                                        {foreach $vo.tow as $k=>$vs}
                                        <label><input type="checkbox" value="{$vs.id}" class="menu{$key}" pid="{$key}"> {$vs.title} </label>
                                        {/foreach}
                                    </div>
                                    {/foreach}

                                </div>
                                <div class='col-sm-6'></div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label"></label>
                                <div class="col-sm-4">
                                    (被选择的栏目可以在该用户后台显示)
                                </div>
                                <div class='col-sm-6'></div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-offset-2 col-sm-9">
                                    <button class="btn btn-sm btn-info" type="button" id="adds">保 存</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
		</div>
	</div>
    <!-- 全局js -->
    <script src="/static/admin/js/jquery.min.js?v=2.1.4"></script>
    <script src="/static/admin/js/bootstrap.min.js?v=3.3.6"></script>
    <!-- 自定义js -->
    <script src="/static/admin/js/content.js?v=1.0.0"></script>
    <script src="/static/admin/js/jquery.min.js"></script>
    <script src="/static/admin/layui/layui.js"></script>
    <!--icheck-->
    <script src="/static/admin/js/plugins/iCheck/icheck.min.js"></script>

    <script>
        /*
         * icheck
         */
        $('input[class^="menu"]').on('ifChanged', function(event){
            var className = $(this).attr("class");
            var pid = $(this).attr("pid");
            var menu = $(".menu"+pid);
            var preObj = $("#parmenu"+pid);
            var s = 0;
            for(i in menu){
                if(menu.eq(i).is(":checked")){
                    s++;
                }
            }
            if(s === 0){
                preObj.prop("checked",false);
            }else if(s >0){
                preObj.prop("checked",true);
            }
        });


        //layui
        layui.use('upload', function(){ //独立版的layer无需执行这一句
            var $ = layui.jquery, layer = layui.layer,upload = layui.upload; //独立版的layer无需执行这一句
            var photo = "";
            //点击提交
            $("#adds").click(function(){
                //获取所有导航复选框
                var jurisdiction = $("input:checkbox");
                //创建新的字符串
                var jur = new Array();
                //循环判断哪些是被选中的，并将vale保存在新字符串jur中
                for(i=0;i<jurisdiction.length;i++){
                    if(jurisdiction.eq(i).is(":checked")) {
                        jur.push(jurisdiction.eq(i).val());
                    }
                }
                jur =  jur.join(",");
                if($("#r_name").val() == ""){
                    layer.msg("请输入角色名称");
                }else{
                    $.post("{:url('Roles/toAdd')}",{pid:$("#pid").val(),r_name:$("#r_name").val(),jurisdiction:jur,sort:$("#sort").val()},function(data){
                        layer.msg(data.msg, {time: 2000}, function () {
                            if (data.url) {
                                window.location.href = data.url;
                            }
                        });
                    })

                }

            });

        });
        //单选和复选框初始化
        $(document).ready(function () {
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });
        });
    </script>
    
    

</body>

</html>
